package com.i2863.shiroDemo.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
public class MenuInfo implements Serializable {

    private static final long serialVersionUID = 6963978927087460846L;
    // 权限ID
    private Integer onlyId;

    //菜单标题
    private String title;

    //菜单链接
    private String href;

    //是否展开
    private boolean spread = false;

    //子菜单列表
    private List<MenuInfo> children;

    public enum ResourceType {

        /**
         * 目录菜单
         */
        TOP_DIRECTORY("top_directory", "顶级目录"),
        DIRECTORY("directory", "目录"),
        MENU("menu", "菜单"),
        BUTTON("button", "按钮");

        private final String code;

        private final String name;

        ResourceType(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public String getName() {
            return name;
        }

        public static List<EnumInfo> getAllEnumInfo() {
            List<EnumInfo> list = new ArrayList<>();
            Arrays.stream(ResourceType.values()).forEach(rt-> list.add(new EnumInfo(rt.getCode(), rt.getName())));
            return list;
        }

    }
}